import sqlite3, re

class Projects():
    db = None
    def __init__(self):
        self.db = sqlite3.connect("db.sqlite").cursor()

    def get_project_id(self, id_or_name):
        if re.match('^[0-9]+$', id_or_name):
            return self._get_id_by_id(id_or_name)
        else:
            return self._get_id_by_name(id_or_name)

    def _get_id_by_id(self, id):
        self.db.execute("SELECT `id` FROM `projects` WHERE `id` = :id", {'id':id})
        result = self.db.fetchone()
        return result[0] if result else None

    def _get_id_by_name(self, name):
        self.db.execute("SELECT `id` FROM `projects` WHERE `name` = :name", {'name':name})
        result = self.db.fetchone()
        return result[0] if result else None